package com.mirai.mirai_boot.controller;

import com.mirai.mirai_boot.service.BaidubaikeService;
import com.mirai.mirai_boot.service.IdiomService;
import com.mirai.mirai_boot.service.MusicService;
import com.mirai.mirai_boot.utils.CutStringUtils;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.sender.Sender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author : CP
 * @version: 1.0
 * @program : mirai_boot
 * @description : 群监听事件
 * @date : 2021-06-29 16:20
 **/
@Service
public class MyGroup {

    @Autowired
    private BaidubaikeService baidubaikeService;

    @Autowired
    private IdiomService idiomService;

    @Autowired
    private MusicService musicService;


    /**
     * 群监听事件
     *
     * @param msg
     * @param sender
     */
    @OnGroup
    public void getGroup(GroupMsg msg, Sender sender) throws IOException {
        System.out.println(msg);

        // 纯文本内容
        String text = msg.getText();
        // 拆分字符串
        CutStringUtils cut = new CutStringUtils(text);

        switch (cut.getType()) {
            case "百科":
                baidubaikeService.findBaike(cut.getPara(), msg, sender);
                break;
            case "点歌":
                musicService.pickMusic(cut.getPara(), msg, sender);
                break;
            case "成语接龙":
                idiomService.startGame(cut.getPara(), msg, sender);
                break;
            default:
                break;
        }

    }
}
